package com.own.component.store.local.configure;

import com.own.component.store.core.Store;
import com.own.component.store.core.property.StoreProperty;
import com.own.component.store.core.util.LockStoreUtil;
import com.own.component.store.core.util.RateLimiterUtil;
import com.own.component.store.local.DefaultLocalStore;
import com.own.component.store.local.util.LocalLockStoreUtil;
import com.own.component.store.local.util.LocalRateLimiterUtil;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;

/**
 * StoreConfigure
 *
 * @author chenxueli
 * @date 2023-07-21 11:27:26
 */
@SuppressWarnings("all")
@SpringBootConfiguration
public class StoreLocalConfigure {

    @Resource
    private StoreProperty storeProperty;

    @Bean
    @ConditionalOnMissingBean(value = Store.class)
    public Store<String> store() {
        return new DefaultLocalStore<>(storeProperty);
    }

    @Bean
    @ConditionalOnMissingBean(value = LockStoreUtil.class)
    public LockStoreUtil lockStoreUtil() {
        return new LockStoreUtil(new LocalLockStoreUtil());
    }

    @Bean
    @ConditionalOnMissingBean(value = RateLimiterUtil.class)
    public RateLimiterUtil rateLimiterUtil() {
        return new LocalRateLimiterUtil();
    }

}
